//
//  SNOrderFormListFooterView.m
//  app
//
//  Created by 王少宁 on 15/5/7.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "SNOrderFormListFooterView.h"

@interface SNOrderFormListFooterView ()
/** 金额总计*/
@property (nonatomic, retain) UILabel * allMoneyLabel;
/** 运费*/
@property (nonatomic, retain) UILabel * primalityLabel;
/** 合计支付*/
@property (nonatomic, retain) UILabel * lastPayLabel;
@property (nonatomic, retain) UILabel * lastPayNumLabel;
@end

@implementation SNOrderFormListFooterView

- (instancetype)init
{
    if ([super init]) {
        [self createView];
    }
    return self;
}

- (void)createView
{
    _allMoneyLabel = CREATE_WITH_FRAME_OF(UILabel, CGPointMake(10, 20),
                                     [self.ubo ow:SCREEN_WIDTH*0.5-10 oh:20]);
    _allMoneyLabel.font = JKAppGlobleFontSmallTagText;
    _allMoneyLabel.textColor = [XCommon hexStringToColor:kColor_l_light_gray_text];
    [self addSubview:_allMoneyLabel];
    
    _primalityLabel = CREATE_WITH_FRAME_OF(UILabel, [_allMoneyLabel.ufo fx:0 fy:1.0 oy:10],
                                           [_allMoneyLabel.ubo fw:1.0 fh:1.0]);
    _primalityLabel.font = JKAppGlobleFontSmallTagText;
    _primalityLabel.textColor = [XCommon hexStringToColor:kColor_l_light_gray_text];
    [self addSubview:_primalityLabel];
    
    _lastPayLabel = CREATE_WITH_FRAME_OF(UILabel, [_allMoneyLabel.ufo ox:SCREEN_WIDTH*0.5 + 30 fy:0],
                                         [_allMoneyLabel.ubo ow:SCREEN_WIDTH*0.5-40 fh:1.0]);
    _lastPayLabel.font = JKAppGlobleFontSmallTagText;
    _lastPayLabel.textColor = [XCommon hexStringToColor:kColor_l_light_gray_text];
    _lastPayLabel.text = @"合计支付:";
    [self addSubview:_lastPayLabel];
    
    _lastPayNumLabel = CREATE_WITH_FRAME_OF(UILabel, [_primalityLabel.ufo ox:SCREEN_WIDTH*0.5 + 30 fy:0],
                                            [_primalityLabel.ubo ow:SCREEN_WIDTH*0.5-40 fh:1.0]);
    _lastPayNumLabel.font = JKAppGlobleFontSmallTagText;
    _lastPayNumLabel.textColor = [UIColor orangeColor];
    [self addSubview:_lastPayNumLabel];
}

- (void)viewWithModel:(SNOrderFormListFooterModel *)model
{
    NSString * allMoneyStr = [NSString stringWithFormat:@"金额总计 :  ￥%.2f",model.lastPayMoeny.floatValue + model.express_fee.floatValue];
    NSMutableAttributedString * allMoneyAttStr = [[NSMutableAttributedString alloc] initWithString: allMoneyStr];
    [allMoneyAttStr addAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:13]} range:NSMakeRange(8, allMoneyStr.length-8)];
    _allMoneyLabel.attributedText = allMoneyAttStr;
    
    NSString * primalityStr = [NSString stringWithFormat:@"配送费用 :  ￥%@",model.express_fee];
    NSMutableAttributedString * primalityAttStr = [[NSMutableAttributedString alloc] initWithString:primalityStr];
    [primalityAttStr addAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:13]} range:NSMakeRange(13, primalityStr.length-13)];
    _primalityLabel.attributedText = primalityAttStr;
    
    _lastPayNumLabel.text = [NSString stringWithFormat:@"￥%@",model.lastPayMoeny];
}

- (void)drawRect:(CGRect)rect
{
    [self drawBackground:rect color:[UIColor whiteColor]];
    [self drawTopLineLeft:0 right:0];
    [self drawSeperatorLineLeft:0 right:0];
    [self drawSingleLineFromPoint:[_allMoneyLabel.ufo ox:SCREEN_WIDTH*0.5 fy:0] toPoint:[_primalityLabel.ufo ox:SCREEN_WIDTH*0.5 fy:1.0] color:[XCommon hexStringToColor:kColor_mm_separator_cell_line]];
}

@end
